<template>
  <el-card style="margin-top: 20px" class="middel-view">
    <template #header>
      <el-menu
        :default-active="activeIndex"
        class="el-menu-demo"
        mode="horizontal"
        @select="handleSelect"
      >
        <el-menu-item index="1">销售额</el-menu-item>
        <el-menu-item index="2">访问量</el-menu-item>
      </el-menu>

      <div class="right">
        <el-radio-group v-model="time" size="small">
          <el-radio-button label="今日"></el-radio-button>
          <el-radio-button label="本周"></el-radio-button>
          <el-radio-button label="本月"></el-radio-button>
          <el-radio-button label="今年"></el-radio-button>
        </el-radio-group>

        <el-date-picker
          v-model="time2"
          type="daterange"
          align="right"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions"
        >
        </el-date-picker>
      </div>
    </template>

    <div class="content">
      <v-chart  :option='getOptions()'/>
      <div class="list-warp">
        <div class="title">门店销售{{activeIndex=='1'?'销售额':'访问量'}}排名</div>
        <div class="list">
          <div class="list-item" v-for="rank in rankData" :key="rank.no">
            <div class="no" :class="{'top-no':rank.no<4}" >{{ rank.no }}</div>
            <div class="name">{{ rank.name }}</div>
            <div class="count">{{ rank.count }}</div>
          </div>
        </div>
      </div>
    </div>
  </el-card>
</template>

<script>
import { mapState } from "vuex";
export default {
  name: "MiddleView",
  data() {
    return {
      activeIndex: "1", // 选中的菜单的标识
      time: "今日", // 选中的时间
      time2: "", // 日期
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  computed: {
    ...mapState({
      orderFullYearAxis: (state) => state.data.reportData.orderFullYearAxis ||[],
      orderFullYear: (state) => state.data.reportData.orderFullYear||[],
      userFullYearAxis: (state) => state.data.reportData.userFullYearAxis||[],
      userFullYear: (state) => state.data.reportData.userFullYear||[],
      orderRank: (state) => state.data.reportData.orderRank||[],
      userRank: (state) => state.data.reportData.userRank||[],
    }),
    rankData() {
      return this.activeIndex === "1" ? this.orderRank : this.userRank;
    },
  },
  methods: {
    // 选中的菜单发生改变的回调
    handleSelect(value, valueList) {
      this.activeIndex = value;
    },
    getOptions(){
     
      const text = this.activeIndex ==='1'?'销售额趋势':'访问量趋势'
      return{
        title:{
          text,
          textStyle:{
            fontSize:14,
            color:'#333'
          },
          lefr:10

        },

        xAxis:{
          data:this.activeIndex === '1'?this.orderFullYearAxis:this.userFullYearAxis,
          axisTick:{
            alignWithLable:true
          }
        },

        yAxis:{
          splitLine:{
            lineStyle:{
              type:'dashed',
              color:'#d43c33'
            }
          }
        },
        series:{
          type:'bar',
          barWidth:'35%',
          data:this.activeIndex==='1'? this. orderFullYear:this.userFullYear
        },

        color:'#3398Db',
        grid:{
          left:50,
          right:50,
          top:50,
          bottom:50
        },
        tooltip:{

        }
      }
    }
  },
};
</script>

<style lang="scss" scoped>
.middel-view {
  // 设置顶部的距离
  margin-top: 20px;
  // 深度选择器 干掉日期的下面的标尺线
  ::v-deep.el-card__header {
    border-bottom: none;
    position: relative;
    padding: 0 20px;
    // height: 32px;
    // 脱标
    .right {
      position: absolute;
      right: 20px; // 右侧的距离
      top: 0;
      height: 100%;
      display: flex;
      align-items: center;
      .el-date-editor {
        margin-left: 20px;
      }
    }
  }
  .content {
    display: flex;
    height: 270px;
    .echarts {
      flex: 5;
      background-color: #eee;
    }
    .list-warp {
      flex: 2;
      .title {
        font-size: 14px;
        color: #333;
        font-weight: 500;
        margin-top: 20px;
      }
      .list {
        margin-top: 15px;
        .list-item {
          display: flex;
          align-items: center;
          height: 20px;
          font-size: 12px;
          margin: 6px 20px 6px 0;
          .no {
            width: 20px;
            height: 20px;
            color: #333;
            display: flex;
            justify-content: center;
            align-items: center;
            &.top-no {
              border-radius: 50%;
              background-color: #000;
              color: #fff;
              font-weight: 300;
            }
          }
          .name {
            margin-left: 10px;
            line-height: 20px;
          }
          .count {
            flex: 1;
            text-align: right;
            line-height: 20px;
          }
        }
      }
    }
  }
}
</style>
